//
//  BellButton.m
//  WangLottery
//
//  Created by 黄修勇 on 12-4-24.
//  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//

#import "BellButton.h"

@implementation BellButton

@synthesize bellState=_bellState;
@synthesize bellColor=_bellColor;
@synthesize number=_number;
@synthesize isProjection=_isProjection;

+(id)creatBellWithFrame:(CGRect)frame{

    BellButton *btn=[BellButton buttonWithType:UIButtonTypeCustom];
    btn.frame=frame;
    [btn setDefault];
    return btn;
}

-(void)setDefault{

    _bellState=BellStateNormal;
    _bellColor=BellColorRed;
    blueImg=[UIImage imageNamed:@"bluebell.png"];
    redImg=[UIImage imageNamed:@"redbell.png"];
    normalImg=[UIImage imageNamed:@"normal.png"] ;
    currentImg=redImg;
    [self setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    [self setTitleColor:[UIColor grayColor] forState:UIControlStateHighlighted];
    [self setBackgroundImage:normalImg forState:UIControlStateNormal]; 
}
-(void)setNumber:(NSInteger)number{

    _number=number;
    [self setTitle:[NSString stringWithFormat:@"%02d",number] forState:UIControlStateNormal];
}

-(void)setBellState:(BellState)bellState{

    if (bellState==_bellState) {
        return;
    }
    _bellState=bellState;
    if (bellState==BellStateNormal) {
        [self setBackgroundImage:normalImg forState:UIControlStateNormal];
        if (_bellColor==BellColorRed) {
            [self setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
        }else
            [self setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
    }else {
        
        [self setBackgroundImage:currentImg forState:UIControlStateNormal];
        [self setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    }
}

-(void)setBellColor:(BellColor)bellColor{

    if (bellColor==_bellColor) {
        return;
    }
    _bellColor=bellColor;
    if (_bellColor==BellColorRed) {
        currentImg=redImg;
        [self setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    }else {
        currentImg=blueImg;
        [self setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
    }
    if (_bellState==BellStateNormal) {
        if (_bellColor==BellColorRed) {
            [self setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
        }else
            [self setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
        [self setBackgroundImage:normalImg forState:UIControlStateNormal];
    }else {
        [self setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [self setBackgroundImage:currentImg forState:UIControlStateNormal];
    }
}

@end
